import router from "../router";
import { Message } from 'element-ui';
import { editByContent } from '@/api/system/auth/authAdminConfig';

export default {
    state: {
        interface: {
            other: {
                closeOnClickModal: true,//系统后台各个弹出层（即模态框）是否通过点击mobile关闭（即点击阴影层关闭模态框）
                clickMenuIsOpenSideMenu: true//点击菜单是否打开侧栏菜单
            },
            color: {
                mainMenuBagColor: '#1E9FFF',//主菜单背景颜色
                mainHoverMenuBagColor: '#1E9FFF',//主菜单hover颜色
            }
        }
    },
    mutations: {
        //初始化站点主题配置
        initSiteThemeData(state, data) {
            state.interface = data.content.interface;
            localStorage.setItem('siteTheme', JSON.stringify(state));
        },
        changeCloseOnClickModal(state, res) {
            state.interface.other.closeOnClickModal = res;
            editByContent({
                'type': 1,
                'content': JSON.stringify(state)
            }).then(res => {
                this.commit('initSiteThemeData', res.data);
            })
        },
        clickClickMenuIsOpenSideMenu(state, res) {
            state.interface.other.clickMenuIsOpenSideMenu = res;
            editByContent({
                'type': 1,
                'content': JSON.stringify(state)
            }).then(res => {
                this.commit('initSiteThemeData', res.data);
            })
        },
        setInterface(state, e) {
            switch (e.type) {
                case 'mainMenuBagColor':
                    state.interface.color.mainMenuBagColor = e.value;
                    break;
                case 'mainHoverMenuBagColor':
                    state.interface.color.mainHoverMenuBagColor = e.value;
                    break;
                case 'closeOnClickModal':
                    state.interface.other.closeOnClickModal = e.value;
                    break;
                case 'clickMenuIsOpenSideMenu':
                    state.interface.other.clickMenuIsOpenSideMenu = e.value;
                    break;
                default:
                    return;
            }
            editByContent({
                'type': 1,
                'content': JSON.stringify(state)
            }).then(res => {
                this.commit('initSiteThemeData', res.data);
            })
        }
    }
}